<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>职位管理页</title>
		<link rel="stylesheet" href="../../lib/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../static/css/font.css">
		<link rel="stylesheet" href="../../static/css/weadmin.css">
		<style>
			.layui-table-cell {
				height: 60px;
				line-height: 60px;
			}
			select{
				width: 150px;
				color: #666;
				height: 38px;
			    line-height: 1.3;
			    border:1px solid #e6e6e6;
			    background-color: #fff;
			    border-radius: 2px;
			    padding-left: 5px;
			}
		</style>
	</head>

	<body>
		<div class="weadmin-nav">
			<span class="layui-breadcrumb" style="visibility: visible;">
		        <a href="">员工管理</a>
		        <a>
	          		<cite>职位列表</cite>
		        </a>
	      	</span>
			<a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
				<i class="layui-icon" style="line-height:30px">ဂ</i>
			</a>
		</div>
		<div class="wrap">
			<blockquote class="layui-elem-quote news_search">
				<div class="layui-inline">
					<a id="" class="layui-btn layui-btn-normal" onclick="WeAdminShow('新增职位','./position-add.html')">添加</a>
				</div>
			</blockquote>
			<!--  门店列表表格 -->
			<table class="layui-table" lay-filter="position_table" id="position_table" style="margin: 0"></table>
		</div>
		<script src="../../publicjs/jquery-1.8.0.min.js"></script>
		<script src="../../lib/layui/layui.js"></script>
		<script src="../../static/js/admin.js" charset="utf-8"></script>
		<script src="../../publicjs/smallkingutil.js"></script>
		<script>
			layui.use(['form', 'table'], function() {
				var table = layui.table;
				var form = layui.form;
				window.form = form;
				// 加载数据表格
				window.positionTable = table.render({
					id: 'positionTable',
					elem: '#position_table',
					url: commonUtil.domain() +'/admin/wxwork/position/list', // 数据接口
					method: 'get',
					page: true, // 开启分页
					request: {
						pageName: 'pageNum', // 分页当前页数发给后台的参数名
						limitName: 'pageSize' // 分页每页多少条发给后台的参数名
					},
					done:function(res){
						$('.layui-laypage-count').text('共'+res.total+'条')
					},
					cols: [
						[ //表头
						    {
								field: 'positionCode',
								title: '职位编号',
								width: 100
							},{
								field: 'positionName',
								title: '职位名称',
								width: 100
							},{
								field: 'note',
								title: '备注',
								width: 200
							},{
								field: 'sortCode',
								title: '排序码',
								width: 100
							},{
								field: 'oper',
								title: '操作',
								width: 100,
								templet: '#oper'
							}
							
						]
					]
				});
				// 刷新表格
				positionTable.refresh = function(data) {
					positionTable.reload({
						where: data,
						page: {
							curr: 1 //重新从第 1 页开始
						}
					});
				}
				// 搜索按钮
				window.positionSearch = function(res){
					var keyword = $('#position_keyword_input').val();
					var provinceCode = $('#province option:selected').data('code');
					var cityCode = $('#city option:selected').data('code');
					var townCode = $('#town option:selected').data('code');
					var positionCode = "";
					if(provinceCode){
						positionCode += provinceCode + "-";
						if(cityCode){
							positionCode += cityCode + "-";
							if(townCode){
								positionCode += townCode;
							}
						}
					}
					var data = {
						keyword: keyword
					}
					if(positionCode && positionCode != ""){
						data.positionCode = positionCode;
					}
					positionTable.refresh(data);
				}
				// 监听表单提交
				table.on('tool(position_table)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
					  var data = obj.data; // 获得当前行数据
					  var layEvent = obj.event; // 获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
					  var tr = obj.tr; // 获得当前行 tr 的DOM对象
					  if(layEvent == 'delete'){ // 点击表格一行的移除按钮
							 layer.confirm("确定要删除此职位吗？", function(index){
								// 发送ajax请求 删除地区
								var ajaxParam = {
									url : commonUtil.domain() + "/admin/wxwork/position/delete",//删除接口地址
									data : {
										positionId : data.positionId
									}
								}
								ajaxUtil.post(ajaxParam, function(){
									layer.closeAll();
									positionTable.refresh();
								});
							 });
					  }else if(layEvent == 'update'){
						  WeAdminShow('修改职位','position-add.html?positionId=' + data.positionId)
					  }
				});
			});
		</script>
		<script type="text/html" id="oper">
  			<a title="修改" lay-event="update"><i class="layui-icon">&#xe642;</i></a>
		    <a title="删除" lay-event="delete"><i class="layui-icon">&#xe640;</i></a>
		</script>
	</body>

</html>